package org.woozoo.xhtml.core.manager.element
{
	import org.woozoo.xhtml.core.base.*;
	
	internal class ElementFactory
	{
		private static var __classByTagName : Object = {};
//		private static var __classByRegExp : Object = {};
		
		public static function addClass(tagName : String, classRef : Class) : void {
			__classByTagName[tagName] = classRef;
		}

//		public static function addRegExp(regExp : String, classRef : Class) : void {
//			__classByRegExp[regExp] = classRef;
//		}
		
		public static function factory(document : Document, source : *, classRef : Class) : Element {
			if (classRef) {
				return new classRef(document, source);
			}
			var localClassRef : Class = Element;
			if (!source) {
				return new localClassRef(document, source);	
			}
			switch (true) {
				case source is XML:
					var tagName : String = (source as XML).localName() as String;
					var classByTagName : Class = __byTagName(tagName);
					if (classByTagName) {
						localClassRef = classByTagName;
					}
				break;
			}
			return new localClassRef(document, source)
		}
		
		private static function __byTagName(tagName : String) : Class {
			if (!tagName) return null;
			return __classByTagName[tagName];
		}
		
//		private static function __byMatch(source : XML) : Class {
//			
//		}
	}
}